package com.jvm.binary.initialize.dynamic_static;

/**
 * 静态分派
 *
 *
 * @author Lizhong
 * @date 2019/3/14
 */


public class StaticDisPatch {
    public void sayHello(Human guy) {
        System.out.println("hello, guy!");
    }

    public void sayHello(Man guy) {
        System.out.println("hello, gentleman!");
    }

    public void sayHello(Woman guy) {
        System.out.println("hello, lady!");
    }

    public static void main(String[] args) {
        Human man = new Man();
        Human woman = new Woman();
        StaticDisPatch sr = new StaticDisPatch();
        sr.sayHello(man);
        sr.sayHello(woman);
        Human man1 = new Human();
        /* // 在没有经过向上转型，向下转型，CastClassException
         * sr.sayHello((Man) man1);
         * sr.sayHello((Woman) man1);
         */
        sr.sayHello(((Man)man));    // 编译时去请了器类型
        sr.sayHello(((Woman)woman));

    }
}

class Human {
}

class Man extends Human {
}

class Woman extends Human {
}